home *** CD-ROM | disk | FTP | other *** search
- Path: surfnet.nl!sun4nl!ittpub!ittpub!nntp
- Newsgroups: comp.lang.c++
- Subject: Re: Why don't you use garbage collection
- Message-ID: <1996Apr12.170708.1835@ittpub>
- From: wil@ittpub.nl (Wil Evers)
- Date: 12 Apr 96 17:07:07 WET
- References: <316D291F.465D@sto.fdata.se>
- Distribution: world
- Nntp-Posting-Host: lintilla
-
- In article <316D291F.465D@sto.fdata.se> Niklas Mellin
- <niklas.mellin@sto.fdata.se> writes:
-
- > No major C/C++ compiler includes a garbage collector, because it is not
- > a part of the C++ language. If you want a garbage collector you should
- > go out looking for a class library that implements it, not for a
- > compiler. A C++ compiler that do garbage collection when you forget
- > delete wouldn't be a C++ compiler.
-
- That depends on what you call garbage collection. If the garbage collector
- would do a `delete' on an unreferenced object, it would not be conforming
- because that would imply the object's destructor is called at a point in
- time when the state of the program is unknown.
-
- However, I don't think there is anything in the ISO C and C++ standards
- that precludes a garbage collector from returning unreferenced objects to
- the pool of free memory.
-
- In my opinion, this subtle difference is why garbage collection would be
- appropriate for C, but not for C++. C++ destructors are often used to
- release other resources than memory. If C++ programmers would get sloppy
- about deleting their heap objects ("don't worry about deleting it, the
- collector will do it for you"), we might end up with too many open file
- descriptors, eternal database locks, forever blocking semaphores and
- expensive telephone bills.
-
- - Wil
-